package com.bjdd.jdy.ui.bindCard;

import com.bjdd.jdy.util.JumpUtil;
import com.bjdd.jdy.util.L;
import com.bjdd.jdy.util.SpUtil;
import com.bjdd.jdy.util.T;

/**
 * Created by Administrator on 2017/5/11.
 */

public class BindCardPresenter extends BindCardContract.Presenter{
    @Override
    public void onStart() {
        if (SpUtil.getUser() == null || SpUtil.getUser().equals("") || SpUtil.getUser().getCarrierId() == null) {
            JumpUtil.toLogin(context);
            return;
        }
        getBank();
    }

    @Override
    void getBank() {
        String token = SpUtil.getToken();
        rxManager.add(model.getBank(token)
        .subscribe(result -> {
            if (!result.isError()){
                view.BankSuccess(result.getData());
            }else {
                T.show(result.getMsg());
            }
        },e -> {
            L.d("错误信息："+e.getMessage());
        }));
    }

    @Override
    void bindCard(String bankCard,String realName, String bankId) {
        String token = SpUtil.getToken();
        String carrierId = SpUtil.getUser().getCarrierId();
        rxManager.add(model.bindCard(token,carrierId,bankCard,realName,bankId)
        .subscribe(result -> {
            if (!result.isError()){
                view.bindSuccess();
            }else {
                T.show(result.getMsg());
            }
        },e -> {
            T.show("绑定失败");
        }));
    }
}
